import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Hi from '@/components/Hi'
import Hi1 from '@/components/Hi1'
import Hi2 from '@/components/Hi2'
import Menu from '@/components/Menu'
import Content from '@/components/Content'
import Count from '@/components/Count'
import Error from '@/components/Error'

Vue.use(Router)

export default new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      name: 'Hello',
      components: {
        default: HelloWorld,
        leftMenu: Menu,
        rightContent: Content
      }
    },
    {
      path: '/count',
      name: 'Count',
      component: Count
    },
    {
      path: '/hi',
      component: Hi,
      alias: '/hiAlias',
      children: [
        {
          path: '/',
          name: 'Hi',
          component: null
        },
        {
          path: 'hi1',
          name: 'Hi1',
          component: Hi1
        },
        {
          path: 'hi2/id/:id(\\d+)/title/:title',
          name: 'Hi2',
          component: Hi2,
          beforeEnter: function (to, from, next) {
            console.log(to)
            console.log(from)
            next({path: '/'})
            // next()函数控制路由跳转,不写的话则不会跳转. 接受参数可以是布尔值.也可以是对象
            // next(true);
            // next({path: '/'}), 该对象会覆盖原先设置的跳转路由
          }
        }
      ]
    },
    {
      path: '/goHome',
      redirect: '/'
    },
    {
      path: '/goH2/id/:id(\\d+)/title/:title',
      name: 'goh2',
      redirect: '/hi/hi2/id/:id(\\d+)/title/:title'
    },
    {
      path: '*',
      component: Error
    }
  ]
})
